# Code and data repository for "Mitigating Emissions Leakage in Incomplete Carbon Markets"

Authors: Meredith L. Fowlie and Mar Reguant

## Description
This repository replicates the results for the paper "Mitigating Emissions Leakage in Incomplete Carbon Markets". It has been run mostly on Stata 16 although one piece of the code uses R.

## Directions
1. Download repository in a folder of your choice.
2. Modify the paths in the ``master_path.do`` file to point to the main directory of the repository.
3. Run ``master_run.do`` to replicate the results in the paper [note: depending on hardware and Stata version, this might take a long time, more than one day]

## Folder and file guide
### 0_build/code
- 1_1_clean_ASM.do: reads, selects, and cleans data from the Annual Survey of Manufacturers.
- 1_2_clean_MECS.do: reads, selects, and cleans data from the Manufacturing Energy Consumption Survey.
- 1_3_clean_QCEW.do: reads, selects, and cleans data from the Quarterly Census of Employment and Wages.
- 1_4_clean_SEDS.do: reads, selects, and cleans data from the State Energy Data System (SEDS).
- 1_5_clean_CarbonIntensities.do: reads and cleans electricity emissions rate data from eGRID (2016).
- 1_6_clean_deflators.do: reads and cleans BLS deflator and producer price index deflator.
- 1_7_clean_trade_data.do: reads and cleans import/export U.S. trade data from Schott, aggregating it to NAICS-year and NAICS-year-country.
- 1_8_clean_IO_table.do: read IxI IO table and perform some NAICS corrections to be consistent with definitions elsewhere.
- 1_9_clean_exiobase.R: clean up exiobase data (in R).

- 2_1_merge_misato_NAICS.do: creates a crosswalk to be able to merge Sato's data.
- 2_2_merge_QCEW_SEDS_MECS.do: merge QCEW, SEDS, MECS, and carbon intensities from eGrid at the NAICS-year-state level.

- 3_1_1_gen_energyprice_domestric.do: combines energy use and energy prices to derive NAICS-year energy prices.
- 3_1_2_1_gen_energyprice_international_regionalpriceindex.do: creates a price index for imports and exports separately as a function of the region (based on Sato's prices).
- 3_1_2_2_gen_energyprice_international_allindustries_regionlevel.do: combines Schott's data with Sato's regional price indices to generate international prices for energy (weighted by US imports and exports) at the NAICS-year level.
- 3_2_1_gen_energyintensities.do: generates time invariant and year-specific industry measures of energy intensity.
- 3_2_2_gen_energyintensities_IO.do: combines energy intensity measures with the IxI IO table to derive comprehensive measures of domestic energy intensity.
- 3_3_gen_carbonintensities.do: creates emissions intensities by year-industry by combining MECS, QCEW, SEDS, and eGrid data. 
- 3_4_gen_prices_intensities_comprehensive.do: combine energy intensity measures to create a measure of comprehensive (including indirect) domestic energy prices.
- 3_5_gen_foreignprices_intensities_comprehensive.do: merges IO tables, foreign energy prices, and energy intensity, to generate comprehensive (including indirect emissions) foreign energy prices.

- 4_create_main_regression_dataset.do: puts together data cleaned in the different steps, homogenizes deflation, labels and prepares dataset for running regressions. Main dataset saved in ``0_build/output/regressions_dataset.dta``

### 1_analyze/code
- 1_run_regressions.do: loop that runs a variety of regressions and stores them in ``1_analyze/output/regressions/regressions_results.dta``
- 2_1_gen_simulation_data.do: Takes the regression dataset and merges in a couple of variables used in the simulations.
- 2_2_gen_transferrate_data.do: Takes ``1_analyze/output/regressions/regressions_results.dta`` and estimate the transfer rate based on the estimated elasticities. It also reshapes the results in different ways to be used in the simulations.
- 3_run_simulations.do: Performs simulations of leakage under alternative assumptions, saves a variety of datasets depending on the simulation specifications.
  
### 2_produce/code
- 1_create_tables.do: generates tables in paper.
- 2_create_figures.do: generates figures in paper.
